package com.bluesky.drcp.presentation.web;

import javax.servlet.ServletContext;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.bluesky.drcp.business.Plugin;
import com.bluesky.drcp.business.logic.DrcpFacade;

/**
 * this class just is used in the UploadPlugin.jsp.
 * 
 * @author HZ00260
 * 
 */
public class SaveFilePluginToDB {
	static public boolean Save(ServletContext servletContext, String name,
			String version, String description, byte[] data) {

		WebApplicationContext wac = WebApplicationContextUtils
				.getRequiredWebApplicationContext(servletContext);
		DrcpFacade drcp = (DrcpFacade) wac.getBean("drcp");

		// got the file,
		Plugin p = new Plugin();
		p.setName(name);
		p.setVersion(version);
		p.setDesc(description);
		p.setData(data);

		drcp.getPluginService().saveOrUpdateByName(p);
		return true;
	}
}
